package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.article.dto.ArticleDto;
import com.heima.model.article.dto.ArticleHomeDto;
import com.heima.model.article.entity.ApArticle;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {

    @Resource
    private ApArticleService apArticleService;

    /**
     * 发布文章
     *
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody ArticleDto dto) {
        return apArticleService.save(dto);
    }

    /**
     * 首页默认加载
     * @param dto
     * @return
     */
    @PostMapping("load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,ArticleConstants.LOAD_TYPE_MORE);
    }

    /**
     * 加载更多
     * @param dto
     * @return
     */
    @PostMapping("loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        return apArticleService.load(dto,ArticleConstants.LOAD_TYPE_MORE);
    }

    /**
     * 加载最新
     * @param dto
     * @return
     */
    @PostMapping(path = "/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto, ArticleConstants.LOAD_TYPE_NEW);
    }

    /**
     * 根据newsId查询文章信息
     * @return
     */
    @PostMapping("query")
    public ApArticle queryByNewsId(@RequestParam("newsId") Long newsId){
        return apArticleService.query(newsId);
    }
}
